.review-docs:
  extends:
    - .default-retry
    - .docs:rules:review-docs
  image: ${GITLAB_DEPENDENCY_PROXY_ADDRESS}ruby:${RUBY_VERSION}-alpine
  stage: review
  needs: []
  variables:
    # We're cloning the repo instead of downloading the script for now
    # because some repos are private and CI_JOB_TOKEN cannot access files.
    # See https://gitlab.com/gitlab-org/gitlab/issues/191273
    GIT_DEPTH: 1
    # By default, deploy the Review App using the `main` branch of the `gitlab-org/gitlab-docs` project
    DOCS_BRANCH: main
  environment:
    name: review-docs/mr-${CI_MERGE_REQUEST_IID}
    # DOCS_REVIEW_APPS_DOMAIN and DOCS_GITLAB_REPO_SUFFIX are CI variables
    # Discussion: https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/14236/diffs#note_40140693
    auto_stop_in: 2 weeks
    url: http://${DOCS_BRANCH}-${DOCS_GITLAB_REPO_SUFFIX}-${CI_MERGE_REQUEST_IID}.${DOCS_REVIEW_APPS_DOMAIN}/${DOCS_GITLAB_REPO_SUFFIX}
    on_stop: review-docs-cleanup
  before_script:
    - source ./scripts/utils.sh
    - install_gitlab_gem

# Always trigger a docs build in gitlab-docs only on docs-only branches.
# Useful to preview the docs changes live.
review-docs-deploy:
  extends: .review-docs
  script:
    - ./scripts/trigger-build.rb docs deploy

# Cleanup remote environment of gitlab-docs
review-docs-cleanup:
  extends: .review-docs
  environment:
    name: review-docs/mr-${CI_MERGE_REQUEST_IID}
    action: stop
  script:
    - ./scripts/trigger-build.rb docs cleanup

docs-lint links:
  extends:
    - .docs:rules:docs-lint
  image: ${REGISTRY_HOST}/${REGISTRY_GROUP}/gitlab-docs/lint-html:alpine-3.18-ruby-3.2.2-4207821e
  stage: lint
  needs: []
  script:
    # Prepare docs for build
    # The path must be 'ee/' because we have hardcoded links relying on it
    # https://gitlab.com/gitlab-org/gitlab-docs/-/blob/887850752fc0e72856da6632db132f005ba77f16/content/index.erb#L44-63
    - mv doc/ /tmp/gitlab-docs/content/ee
    - cd /tmp/gitlab-docs
    # Build HTML from Markdown
    - make compile
    # Check the internal links and anchors (in parallel)
    - "parallel time bundle exec nanoc check ::: internal_links internal_anchors"

.docs-markdown-lint-image:
  # When updating the image version here, update it in /scripts/lint-doc.sh too.
  image: ${REGISTRY_HOST}/${REGISTRY_GROUP}/gitlab-docs/lint-markdown:alpine-3.18-vale-2.27.0-markdownlint-0.35.0-markdownlint2-0.8.1

docs-lint markdown:
  extends:
    - .default-retry
    - .docs:rules:docs-lint
    - .docs-markdown-lint-image
    - .yarn-cache
  stage: lint
  needs: []
  script:
    - source ./scripts/utils.sh
    - yarn_install_script
    - scripts/lint-doc.sh

docs-lint blueprint:
  extends:
    - .default-retry
    - .docs:rules:docs-blueprints-lint
  image: ${GITLAB_DEPENDENCY_PROXY_ADDRESS}ruby:${RUBY_VERSION}-slim
  stage: lint
  needs: []
  script:
    - scripts/lint-docs-blueprints.rb

docs code_quality:
  extends:
    - .reports:rules:code_quality
    - .docs-markdown-lint-image
  stage: lint
  needs: []
  dependencies: []
  allow_failure: true
  script:
    - vale --output=doc/.vale/vale-json.tmpl --minAlertLevel warning doc > gl-code-quality-report-docs.json || exit_code=$?
  artifacts:
    reports:
      codequality: gl-code-quality-report-docs.json
    paths:
      - gl-code-quality-report-docs.json
    expire_in: 2 weeks
    when: always

ui-docs-links lint:
  extends:
    - .docs:rules:docs-lint
    - .static-analysis-base
    - .ruby-cache
  stage: lint
  needs: []
  script:
    - bundle exec haml-lint -i DocumentationLinks

docs-lint deprecations-and-removals:
  variables:
    SETUP_DB: "false"
  extends:
    - .default-retry
    - .ruby-cache
    - .default-before_script
    - .docs:rules:deprecations-and-removals
  stage: lint
  needs: []
  script:
    - bundle exec rake gitlab:docs:check_deprecations
